import 'base_state.dart';
import 'base_view_model.dart';

///自定义State 用于基础Page的
abstract class BaseMvvmState<T extends BasePage, VM extends BaseViewModel> extends BaseState<T> {
  //主要的ViewMode
  late VM vm;

  BaseMvvmState(VM? vvm) {
    initVm(vvm);
  }

  void initVm(VM? vvm) {
    if (vvm != null) {
      vm = vvm;
    }
  }

  @override
  void initState() {
    super.initState();
    if (vm.lifecycleOwner != this) {
      vm.isFirst = true;
    }
    vm.lifecycleOwner = this;
    vm.initState();
  }

  @override
  void dispose() {
    if (!vm.isDispose) {
      vm.dispose();
    }
    super.dispose();
  }
}
